Flow Analysis in the Geometry of Interaction
نویسندگان
چکیده
ion O1 = b p(I2) [ b q(I3) O2 = p b(I1) O3 = q b(I1) b 7654 0123 ?? p __ q ??????? Sharing O1 = r(I2) [ s(I3) O2 = r (I1) O3 = s (I1) 4?? r __ s ??????? Weakening O1 = ; 7654 0123 Conditional O1 = I3 [ I4 O2 = I1 O3 = I2 O4 = I2 if >>>>>>> Unary functions O1 = I2 O2 = I1 f f Constants O1 = I1 c 7654 0123 Non-local variables O1 = bt (I2) O2 = tb (I1) b ? 7654 0123 t Application O1 = q d (I2) O2 = dq(I1) [ dp(I3) O3 = p d (I2) q @ 7654 0123 ?? d __ p ??????? Fig. 1. Flow equations for nodes. Ports numbered counter-clockwise from top. De nition6. Edge e between ports x and y gives rise to the equations Ix = Oy Iy = Ox This set is denoted by Ee. Together with the equations for each node this de nes the complete set of equations representing the ow of information of the program. We note that since a node has at most four ports and that one port can be linked to at most one other port, the number of equations arising from a graph is linear in the number of nodes in the graph. De nition7. The ow equations EG of a -graph G = (N;E) is the set EG = [ n2N En [ [ e2E Ee: @ r s d q p O1 = r(I2) [ s(I3) O2 = r (I1) O3 = s (I1) O4 = q d (I5) O5 = dq(I4) [ dp(I6) O6 = p d (I5) I1 = O4 I4 = O1 I6 = O3 I3 = O6 Fig. 2. Flow equations for recursion. For a -graph of a closed expression there will be exactly one port in the graph that is not linked to other ports; we call this the principal port and number it 0. This port is the input port for the program where the initial state of the computation is speci ed. A speci c equation must de ne the possible set of input states, Iinit . De nition8. The collecting semantics [5], [[G]]coll of a -graph G is the set of descendants of the initial state at each port P : [[G]]coll(P ) = fs j 9s0 2 Iinit : (I0; s0) ! (P; s)g The following theorem gives a least xed point characterisation of the collecting semantics. Its proof follows from [3]. Theorem9. The collecting semantics [[G]]coll is the smallest solution to the equation set EG [ fI0 = Iinitg in the complete lattice (P(States); ). 4.1 Example: equations for recursion Recall that a recursion node was obtained by linking a sharing node and an application node by combining the unlabelled port of the sharing node with the q-labelled port of the application node. The resulting graph has two unlinked ports, the other four being linked together. Figure 2 shows the graph with its set of ow equations where the latter four equations arise from the way the two nodes are linked together. We would like to reduce this to a set of equations only in the variables of the ports that are not linked together, i.e., to a set of equations in the variables O2; I2; O5; I5. After a series of calculations using the path algebra from Section 3 we obtain the following two ow equation for the compound recursion node: O2 = r q d (I5) O5 = dqr(I2) [ dqsp d (I5) [ dps q d (I5) Using these equations we can now treat recursion as an atomic node of the graph. De nition10. The recursion operator is translated into a two-port recursion node with ow equations as follows: I1=O1 rec GFED @ABC I2=O2 O1 = r q d (I2) O2 = dqr(I1) [ dqsp d (I2) [ dps q d (I1) 5 Analyses In this section we show how various kinds of information can be extracted from the collecting semantics. We consider strictness properties, the ow of functional data objects (closures) and the number of use of data. 5.1 Strictness We recall that a function is called strict if the result of applying the function to an unde ned argument is unde ned. In our framework, a result of a computation is unde ned if the set of output states of the graph is empty. The ow equation for an unde ned argument, ? is therefore simply O? = ;. Denoting by Of and If the principal port of the function we are analysing, we thus have to decide under which conditions the set of output state, O0 for the graph I0=O0 q @ 7654 0123 If=Of ::d v v v v v v v v v v I?=O? dd p IIIIIIIIII is empty. The graph has ow equations 8>><>:O0 = q d (Of ) If = dq(I0) [ dp(O?) = dq(I0) + equations for f From this we see that a su cient condition for O0 to be empty is that every state in Of has a p on top of the stack. Furthermore, we are always certain to have a q on top of the stack in the set If . Writing hx : M;Ei for the set of states where the fp; qg-stack has an x on top of the stack, the above observations justify the following strictness criterion: Proposition11. A function represented by graph G with principal port f is strict if If hq : M;Ei ) Of hp : M;Ei: d q p p q s r λ λ @ 1 2 p q Fig. 3. x:( y:x)x This strictness criterion allows to check for strictness when the argument to the higher-order function is of base type. For higher-order arguments we can represent the situation where the argument is completely unde ned and prove properties based on this fact. However, in order to prove properties such as Twice(f ) = x :f (f (x )) is strict if f is strict we need to replace f with a graph that represents all strict functions, i.e., a graph with the input-output behaviour described by the strictness criterion from above, and then solve the equations with this as input. Thus the analysis does not function as the strictness analysis of Burn et. al. [2] which will tabulate the entire abstraction of a higher-order function. The information must be obtained by posing speci c questions to the analyser. 5.2 Usage analysis The collecting semantics contains information about the use of values during evaluation. The information of interest is whether the value of a given expression is never used or is used at most once. With this style of information it is possible to avoid storing data that is never used in the subsequent computation. We give a small example to show the kind of information we can nd. In the -graph in Fig. 3 the function 2 does not use its argument. This means that the set of states entering on the p-branch of 2 is empty, therefore no states arriving at the d-branch of the application node will have a p on top of the stack hence the set of states travelling down the p-branch will be empty. This means that the r-branch will receive an empty set of states hence the states leaving the sharing nodes can only have an s on top of their fr; sg-stack. Thus the analysis has shown that the argument to the application node will not be used and that the argument to 1 will be used at most once. More generally we can identify functions that have multiple occurrences of bound variables, but only use a subset of them to access their arguments. 5.3 Closure analysis Let e1@e2 stand for the application of the function obtained by evaluating e1 to the argument e2. Which function is obtained will usually depend on the run-time arguments to the program as in v: : : : ( x:x+ v)@e2 : : : and a given expression can evaluate to di erent functions if evaluated in di erent contexts as is the case if it is part of a functions that is called several times. A controlow analysis (also called closure analysis by Sestoft [15, 16]) will determine an approximate description of the set of functions that an expression can evaluate to during execution of a program. We shall follow the approach taken in Sestoft's analysis and Shivers' 0-CFA analysis [17] and abstract a function to the -expression it was obtained from, i.e., we ignore the environment of a closure. We assume that the nodes in the graph G are given unique names. This naming is extended to the labels by subscripting all labels of an edge of the node named ` with the name `. This means that for a state hp` : m; ei we can tell which node pushed the p on the stack. We recall that when entering an application node labelled `, a q` is pushed onto the stack. When the corresponding node is entered, this q` is removed from the stack. Let n be the !-port of a node. The set of application nodes that this can be passed to as a function is therefore included in the set f` : hq` : m; ei 2 [[G]]coll(In)g i.e., the set of labels ` such that hq` : m; ei is an input state at the principal port of the node. Dually, the set of nodes that can appear as functions at an application node with d-port n is approximated by the set f` : hq` : m; ei 2 [[G]]coll(In)g of labels of qs pushed onto the stack when control returns from evaluation of the body of a -expression. An important di erence between this analysis and Sestoft's closure analysis is that this analysis takes the call-by-name evaluation order into account because it combines informationabout closures with the usage information described above. If the analysis can detect of an expression that it is never evaluated (i.e., the set of input states on the principal port of the corresponding graph is empty) then no bindings from this expression will appear in the nal result. In contrast to this, Palsberg [11] has showed that closure analysis is valid under all evaluation strategies and must therefore take call-by-value evaluation into account. This would include the closures in the unused argument (Shivers' analysis is for a call-by-value language so this remark is irrelevant for his analysis). 6 Conclusion We have presented a new framework to reason about properties of higher-order call-by-name functional programs coming from an intensional semantics: the Geometry of Interaction. The goal was to analyse properties that cannot be characterised by extensional means, and to treat di erent analyses in one framework. Choosing the Geometry of Interaction as semantic foundation carries perhaps an initial cost since it is not widely known. In our opinion this is out-weighed bythe ease with which one passes by from semantics to collecting semantics andto a computable approximation. Our work builds upon [4, 5, 3], and continuesand concretises a line of work suggested by Jones [9] who proposed to apply ab-stract interpretation to an environment-based evaluator for the -calculus. Theoperational semantics chosen here is in fact a re nement of Jones' evaluator; thisre nement leads to simpler abstract operations and allows to extract the owequations in a straightforward manner. A similar approach, but for a call-by-value evaluator, was considered by Deutsch [7] for aliasing and life-time analysisof higher-order functions.Other approaches in the eld of closure analysis include Shivers' [17] where hedevelops a denotational semantics for Scheme with enough operational contentto obtain his controlow analyses by abstraction. Although an impressive pieceof semantics, it is probably too costly to develop the denotational semantics forevery new analysis, compared to what is gained from the the generic principlesfor abstracting such a semantics. Sestoft [16] proves the correctness of his clo-sure analysis with respect to Krivine's abstract machine. This is closer to ourapproach but he does not consider how the analysis could be derived from themachine. The balanced traces used by Sestoft to identify matching applicationand nodes seems to correspond closely to the notion of well-balanced path inthe Geometry of Interaction. We have not yet established an exact relationshipbetween these analyses and ours, nor can we state an exact comparison betweenour strictness analysis and the one cited.The Cousot and Cousot framework [6] has broader scope than the presentwork since it deals with abstracting higher-order functions in general. As anapplication they de ne a comportment analysis that generalises classical strict-ness and termination analysis. Our approach circumvent the use of lattices offunctions and relations by passing to the abstract machine level. Evidently thisnarrows the scope of application to normal order evaluation of higher-order func-tions but allows simple correctness proofs and implementation scheme.The analysis framework so obtained is exible in that several kinds of proper-ties can be expressed with the collecting semantics and a range of approximationtechniques for stacks, lists and multisets can and must be employed to abstractthe states of the Geometry of Interaction machine. Given the abstractions, theimplementation of the analyses is simple since it only involves solving a set ofow equations. The calculations themselves are straightforward but the resultstend to be unwieldy; this together with space considerations have prevented usfrom including examples of analyses.Further work also involves using the path semantics to argue the correctnessof various evaluation-order analyses. These cannot be formalised by consideringindividual sets of states; traces are needed. It is also hoped that complexityissues such as those studied by Sands [14] can be dealt with here. The semanticsshould be su ciently ne-grained to express a faithful complexity measure forhigher-order programs. References1. A Asperti, V Danos, C Laneve, and L Regnier. Paths in the -calculus: Threeyears of communication without understanding. In Proceedings, Ninth AnnualIEEE Symposium on Logic in Computer Science, pages 426 436. IEEE ComputerSociety Press, 1994.2. G Burn, C Hankin, and S Abramsky. The theory and practice of strictness analysisfor higher order functions. Science of Computer Programming, 7:249 278, 1986.3. P Cousot. Semantic foundations of program analysis. In N Jones and S Muchnick,editors, Program ow analysis : theory and application, pages 303 342. Prentice-Hall, 1981.4. P Cousot and R Cousot. Abstract interpretation: A uni ed lattice model for staticanalysis of programs by construction of approximations of xpoints. In Proc. of4th ACM Symposium on Principles of Programming Languages, pages 238 252,Los Angeles, CA, 1977. ACM Press, New York.5. P Cousot and R Cousot. Systematic design of program analysis frameworks. InProc. 6th ACM Symposium on Principles of Programming Languages, pages 269282, San Antonio, Texas, 1979. ACM Press, New York.6. P Cousot and R Cousot. Higher-order abstract interpretation (and applicationto comportment analysis generalising strictness, termination, projection and PERanalysis of functional languages. In Proceedings of 1994 International Conferenceon Computer Languages, pages 95 112. IEEE Computer Society Press, 1994.7. A Deutsch. On determining lifetime and aliasing of dynamically allocated data inhigher-order functional speci cations. In Proc. of 17. ACM Symposium on Princi-ples of Programming Languages, pages 157 168, San Francisco, 1990. ACM Press.8. J.-Y Girard. Towards a Geometry of Interaction. In J. W Gray and A Scedrov,editors, Categories in Computer Science and Logic, volume 92 of ContemporaryMathematics, pages 69 108. American Mathematical Society, 1989.9. N Jones. Flow analysis of lambda expressions. In S Even and O Kariv, editors,Proc. of 8th International Colloquium on Automata, Languages and Programming,pages 114 128. Springer LNCS vol. 115, 1981.10. I Mackie. The geometry of interaction machine. In Proceedings, 22nd ACM Sym-posium on Principles of Programming Languages, pages 198 208, 1995.11. J Palsberg. Closure analysis in constraint form. ACM Trans. on ProgrammingLanguages and Systems, 17(1):47 62, 1995.12. S. L Peyton Jones. The Implementation of Functional Programming Languages.Prentice Hall International, 1987.13. G Plotkin. LCF considered as a programming language. Theoretical ComputerScience, 5(3):223 256, 1977.14. D Sands. A naive time analysis and its theory of cost equivalence. Journal of Logicand Computation, 5(4):495 541, 1995.15. P Sestoft. Replacing function parameters by global variables. Master's thesis,Univ. of Copenhagen, 1988.16. P Sestoft. Analysis and E cient Implementation of Functional Programs. PhDthesis, DIKU, University of Copenhagen, 1991. Available as DIKU Report 92/6.17. O Shivers. Control-Flow Analysis of Higher-Order Languages or Taming Lambda.PhD thesis, Carnegie-Mellon University, 1991.This article was processed using theLATEX macro package with LLNCS style
منابع مشابه
Acoustic-Mean Flow Interaction in Solid Propellant Rocket Motors
There are several sources for pressure oscillations in solid propellant rocket motors. Oscillatory flow field is one of them. Free shear layers in motor flow field cause vortex shedding. End edges of propellant grains and baffle edge in two-segmented motors are samples of such zones. These vortices move from their forming points and strike the field walls. The kinetic energy of vortices change ...
متن کاملAcoustic-Mean Flow Interaction in Solid Propellant Rocket Motors
There are several sources for pressure oscillations in solid propellant rocket motors. Oscillatory flow field is one of them. Free shear layers in motor flow field cause vortex shedding. End edges of propellant grains and baffle edge in two-segmented motors are samples of such zones. These vortices move from their forming points and strike the field walls. The kinetic energy of vortices change ...
متن کاملNumerical simulation of flow hydrodynamic around dolphin body in viscous fluid
The biomimetic and hydrodynamic study of aquatic animals is one of the most challenging computational fluid dynamics topics in recent studies due to the complexity of body geometry and the type of flow field. The movement of the aquatic body, and particularly the tail section and the corresponding movement of fluid around the body, causes an unsteady flow and requires a comprehensive study of t...
متن کاملPrediction of Temperature Distribution in the Hot Torsion Test Specimen
Hot torsion test (HTT) has extensively been used to analysis and physically model flow behavior and microstructure evolution of materials and alloys during hot deformation processes. In this test, the specimen geometry has a great influence in obtaining reliable test results. In this paper, the interaction of thermal-mechanical conditions and geometry of the HTT specimen was studied. The commer...
متن کاملPerformance Analysis of a Variable Geometry Turbocharger Using Mean Line Method
Turbocharging an engine boosts its power by increasing the amount of input air. This task is accomplished by using the exhaust gas to power a turbine which is engaged with a compressor. The Variable Geometry Turbocharger, VGT is a unique turbocharger that the diffuser vane angle can be changed over a wide range of positions. The mathematics of turbomachinery flow analysis is intensive and uses ...
متن کاملSHAPE OPTIMIZATION OF CONCRETE GRAVITY DAMS CONSIDERING DAM–WATER–FOUNDATION INTERACTION AND NONLINEAR EFFECTS
This study focuses on the shape optimization of concrete gravity dams considering dam–water–foundation interaction and nonlinear effects subject to earthquake. The concrete gravity dam is considered as a two–dimensional structure involving the geometry and material nonlinearity effects. For the description of the nonlinear behavior of concrete material under earthquake loads, the Drucker–Prager...
متن کامل